/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servlets;

import Tag.QuestionEntity;
import Tag.QuestionEntityFacade;
import data.BuildingEntity;
import data.BuildingEntityFacade;
import java.io.IOException;
import java.io.PrintWriter;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author ajou
 */
@WebServlet(name = "QuestionServlet", urlPatterns = {"/QuestionServlet"})
public class QuestionServlet extends HttpServlet {
    @EJB
    private BuildingEntityFacade bef;

    @EJB
    private QuestionEntityFacade qef;

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

        qef.create(new QuestionEntity("Which one is correct? (An ordered list in which insertions and deletions are made at one end called the top. )", "Tree", "Stack", "Queue", "Array", 2, 1));
        qef.create(new QuestionEntity("Where is College of Information and Technology office?", "507-1", "310", "307", "108", 1, 2));
        qef.create(new QuestionEntity("Which one does not sell in Paldal cafeteria?", "Sandwich", "Bibimbab", "Ramen", "Kimbab", 1, 3));
        qef.create(new QuestionEntity("Where is the professor Kim kihyeong's lab?", "Sanhak516", "Sanhak506", "Sanhak526", "Sanhak510", 1, 4));
        qef.create(new QuestionEntity("Does cafeteria exist in Sanhak?", "Yes", "No", null, null, 1, 5));
        qef.create(new QuestionEntity("How many floors in Sanhak Hall?", "9", "10", "11", "12", 3, 6));
        qef.create(new QuestionEntity("Which is the name of cafeteria in frond of East Hall?", "Domitory cafeteria", "Student Union cafeteria", "Ahyang", "Palmae", 3, 7));
        qef.create(new QuestionEntity("1, 4, 8, 13, ... What is the next number?", "10", "18", "19", "21", 3, 11));
        qef.create(new QuestionEntity("Which is the diagram that does NOT match each other?", "Star shape", "Triangle shape", "Rectangle shape", "Circle", 4, 12));
        qef.create(new QuestionEntity("What is NOT the main element that makes up body?", "Carbohydrate", "Protein", "Lipid", "Calcium", 4, 10));
        qef.create(new QuestionEntity()); // West11
        qef.create(new QuestionEntity()); // West12
        qef.create(new QuestionEntity("Which one is NOT correct?", "Hello: Moi", "Thank you: Kiitos", "Sorry: Anteeksi", "Good morning: Hyvaa yota", 4, 13));
        qef.create(new QuestionEntity("Who is NOT professor of Business Management Departmant?", "Kim Kwangyun", "Hwang Yerock", "Hong Manpyo", "Song Yeongkeun", 3, 14));
        qef.create(new QuestionEntity()); // Da15
        qef.create(new QuestionEntity("How many months have 28th day?", "1", "2", "5", "12", 4, 16));
        qef.create(new QuestionEntity("If a woman is 21 and is half age of her mom, how old will be the mom when the woman is 42?", "84", "42", "63", "21", 3, 17));
        qef.create(new QuestionEntity("A rancher has 33 head of cattle standing in a field, when suddenly a bolt of lightning kills all but 9 of them. How many head of cattle are left standing?", "0", "9", "24", "33", 2, 18));
        qef.create(new QuestionEntity("When did professor Teemu become vegetarian?", "When he was 20 years old.", "When he was 25 years old.", "When he was 30 years old.", "He is not vegetarian.", 1, 19));
        qef.create(new QuestionEntity("Who is the oldest man in IT Intensive Programming class?", "Jeong Hocheol", "Park Dongjoo", "Seo Chorong", "Song Byeongjoon", 4, 20));
        qef.create(new QuestionEntity("In distributed component communication, the client calls the server component's motheods through", "a stub", "a skeleton", "a container box", "a singleton", 1, 21)); // Cap21
        qef.create(new QuestionEntity("What is the name of cafe in Student Union?", "Bonespe", "Good", "Banila Factory", "Haha", 3, 22));
        qef.create(new QuestionEntity("Which is NOT name of student club of Ajou University?", "Hanel uem-pyo", "Soul", "Mass", "2.5g", 3, 23));
        qef.create(new QuestionEntity("How many beverage vending machines in Student Union?", "3", "4", "5", "6", 3, 24));
        qef.create(new QuestionEntity("Who is famous professor in Electronic Engineering Department?", "Kim Sanbae", "Hwang Yerock", "Song Yeongkeun", "Hong manpyo", 1, 25));
        qef.create(new QuestionEntity("Does ATM exist in Woncheon Hall?", "Yes", "No", null, null, 1, 26));
        qef.create(new QuestionEntity("Does restroom exist in 4th floor of Woncheon Hall?", "Yes", "No", null, null, 2, 27));
        qef.create(new QuestionEntity("Which is the word that does NOT match with others?", "Sea", "Sand", "Seashore", "Swimming", 2, 28));
        qef.create(new QuestionEntity("If (All car color is green), which sentence is true?", "Truck's color is not green.", "Sonata's color is black.", "Small car's color is green.", "Train's color is green.", 3, 29));
        qef.create(new QuestionEntity("Which is the other name of Seongho Hall?", "Jongseoldong", "Jipgyodong", "Buphakgwan", "Dongbang", 3, 30)); // Seong30
        
        for (BuildingEntity b : bef.findAll()) {
            if (b.getName().equals("Paldal Hall")) {
                for (int i=0; i<3; i++)
                    b.addQuestion(i+1);
            } else if (b.getName().equals("Sanhak Hall")) {
                for (int i=3; i<6; i++)
                    b.addQuestion(i+1);
            } else if (b.getName().equals("East hall")) {
                for (int i=6; i<9; i++)
                    b.addQuestion(i+1);
            } else if (b.getName().equals("West Hall")) {
                for (int i=9; i<12; i++)
                    b.addQuestion(i+1);
            } else if (b.getName().equals("Dasan Hall")) {
                for (int i=12; i<15; i++)
                    b.addQuestion(i+1);
            } else if (b.getName().equals("Yulgok Hall")) {
                for (int i=15; i<18; i++)
                    b.addQuestion(i+1);
            } else if (b.getName().equals("Capstone Design Laboratory")) {
                for (int i=18; i<21; i++)
                    b.addQuestion(i+1);
            } else if (b.getName().equals("Student Union")) {
                for (int i=21; i<24; i++)
                    b.addQuestion(i+1);
            } else if (b.getName().equals("Woncheon Hall")) {
                for (int i=24; i<27; i++)
                    b.addQuestion(i+1);
            } else if (b.getName().equals("Seongho Hall")) {
                for (int i=27; i<30; i++)
                    b.addQuestion(i+1);
            }
        }
        
        try {
            /* TODO output your page here. You may use following sample code. */
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet QuestionServlet</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet QuestionServlet at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
